# encoding=utf-8


import pytest
import os
from common.cmd import command
from emails.get_email_and_report_params import Report, Email
from emails.mail_content import Content
from emails.send import SendEmail
from emails.set_report_title import SetTitle
from emails.set_win_title import set_windows_title


def main():
    """
    执行用例并生成allure报告
    """
    pytest.main()
    # 自定义报告中的environment
    command('environment.properties', r'.\allure-results\environment.properties')
    os.system(r"allure generate -c -o allure-results/report")
    # 复制bat文件到allure-results目录下，用于打开测试报告
    command('打开测试报告.bat', r'.\allure-results\打开测试报告.bat')
    # 自定义浏览器标签名称
    set_windows_title(Report.win_title)
    # 自定义报告标题
    json_data = SetTitle().get_json_data(Report.report_title)
    SetTitle().write_json_data(json_data)
    e = SendEmail(Email.server, Email.sender, Email.password, int(Email.port))
    # 压缩测试报告
    e.zipDir(Report.zip_name, 'allure-results')
    e.send_email(Email.subject, Content().html_content, Report.zip_name, Email.receiver)
    # 删除本次压缩测试报告
    os.system(rf'del  {Report.zip_name}')


if __name__ == '__main__':
    main()
    # pytest.main()
